Open
Conversation
Comment on lines
1
to
+5
| #ifndef HYPERCALL_H | ||
| #define HYPERCALL_H | ||
| #include "linux/types.h" | ||
|
|
||
| static inline void igloo_hypercall(unsigned long num, unsigned long arg1) { | ||
| #if defined(CONFIG_MIPS) | ||
| register unsigned long reg0 asm("v0") = num; | ||
| register unsigned long reg1 asm("a0") = arg1; | ||
|
|
||
| asm volatile( | ||
| "movz $0, $0, $0" | ||
| : "+r"(reg0) | ||
| : "r"(reg1) // num in register v0 | ||
| : "memory" | ||
| ); | ||
|
|
||
|
|
||
| #elif defined(CONFIG_ARM64) | ||
| register unsigned long reg0 asm("x8") = num; | ||
| register unsigned long reg1 asm("x0") = arg1; | ||
| asm volatile( | ||
| "msr S0_0_c5_c0_0, xzr \n" | ||
| : "+r"(reg1) | ||
| : "r"(reg0) | ||
| : "memory" | ||
| ); | ||
| #elif defined(CONFIG_ARM) | ||
| register unsigned long reg0 asm("r7") = num; | ||
| register unsigned long reg1 asm("r0") = arg1; | ||
|
|
||
| asm volatile( | ||
| "mcr p7, 0, r0, c0, c0, 0" | ||
| : "+r"(reg1) | ||
| : "r"(reg0) | ||
| : "memory" | ||
| ); | ||
| #elif defined(CONFIG_X86_64) | ||
| register unsigned long reg0 asm("rax") = num; | ||
| register unsigned long reg1 asm("rdi") = arg1; | ||
|
|
||
| asm volatile( | ||
| "cpuid" | ||
| : "+r"(reg0) // hypercall num + return value in rax | ||
| : "r"(reg1) // arguments | ||
| : "memory", "ebx", "ecx", "edx" // No clobber | ||
| ); | ||
| #else | ||
| #error "No igloo_hypercall support for architecture" | ||
| #endif | ||
| } | ||
|
|
||
| static inline unsigned long igloo_hypercall2(unsigned long num, unsigned long arg1, unsigned long arg2) { | ||
| #if defined(CONFIG_ARM64) | ||
| register unsigned long reg0 asm("x8") = num; | ||
| register unsigned long reg1 asm("x0") = arg1; | ||
| register unsigned long reg2 asm("x1") = arg2; | ||
| asm volatile( | ||
| "msr S0_0_c5_c0_0, xzr \n" | ||
| : "+r"(reg1) // Input and output | ||
| : "r"(reg0), "r"(reg2) | ||
| : "memory" | ||
| ); | ||
| return reg1; | ||
| #elif defined(CONFIG_ARM) | ||
| register unsigned long reg0 asm("r7") = num; | ||
| register unsigned long reg1 asm("r0") = arg1; | ||
| register unsigned long reg2 asm("r1") = arg2; | ||
|
|
||
| asm volatile( | ||
| "mcr p7, 0, r0, c0, c0, 0" | ||
| : "+r"(reg1) // Input and output | ||
| : "r"(reg0), "r"(reg2) | ||
| : "memory" | ||
| ); | ||
|
|
||
| return reg1; | ||
|
|
||
| #elif defined(CONFIG_MIPS) | ||
| register unsigned long reg0 asm("v0") = num; | ||
| register unsigned long reg1 asm("a0") = arg1; | ||
| register unsigned long reg2 asm("a1") = arg2; | ||
|
|
||
| asm volatile( | ||
| "movz $0, $0, $0" | ||
| : "+r"(reg0) // Input and output in R0 | ||
| : "r"(reg1) , "r" (reg2)// arg2 in register A1 | ||
| : "memory" | ||
| ); | ||
| return reg0; | ||
| #elif defined(CONFIG_X86_64) | ||
| register unsigned long reg0 asm("rax") = num; | ||
| register unsigned long reg1 asm("rdi") = arg1; | ||
| register unsigned long reg2 asm("rsi") = arg2; | ||
|
|
||
| asm volatile( | ||
| "cpuid" | ||
| : "+r"(reg0) // hypercall num + return value in rax | ||
| : "r"(reg1), "r"(reg2) // arguments | ||
| : "memory", "ebx", "ecx", "edx" | ||
| ); | ||
|
|
||
| return reg0; | ||
| #else | ||
| #error "No igloo_hypercall2 support for architecture" | ||
| #endif | ||
| } | ||
|
|
||
| #endif | ||
| #include "libhc/hypercall.h" | ||
| #endif No newline at end of file |
There was a problem hiding this comment.
Why does this file still exist? Shouldn't you just make all the places that include hypercall.h include libhc/hypercall.h?
Contributor
Author
There was a problem hiding this comment.
The header guard and linux/types.h requirement is unique to the kernel. Though I'm now double checking that the linux types.h is true. If it's not then I'll just add the the header guard to libhc
Contributor
Author
There was a problem hiding this comment.
types is no longer required for reasons I don't know.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.